package com.jack.charging.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author Jack
 * @date 2025/2/7 17:22
 * @see
 * @since
 */
@Slf4j
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
    private static final String BASE_PACKAGE ="com.jack.charging";
    private static final String GROUP_NAME ="智慧充电云平台";
    private static final String HOST ="http://charging.jack.com";
    private static final String TITLE ="智慧充电云平台-在线API文档";
    private static final String DESCRIPTION ="智慧充电云平台-在线API文档";
    private static final String TERMS_OF_SERVICE_URL ="http://www.apache.org/licenses/LICENSE-2.0";
    private static final String CONTACT_NAME ="Jack";
    private static final String CONTACT_URL ="http://www.jack.com";
    private static final String CONTACT_EMAIL ="jack@qq.com";
    private static final String VERSION ="1.0";

    public Knife4jConfiguration() {
        log.info("初始化Knife4jConfiguration");
    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName(GROUP_NAME)
                .select()
                .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(TITLE)
                .description(DESCRIPTION)
                .termsOfServiceUrl(TERMS_OF_SERVICE_URL)
                .contact(new Contact(CONTACT_NAME, CONTACT_URL, CONTACT_EMAIL))
                .version(VERSION)
                .build();
    }
}
